﻿using System;
using NUnit.Framework;
using Tamias.BasicCmsPortableArea.Domain;
using Tamias.DefaultImplementation.Data;
using Tamias.UnitTests;

namespace Tamias.DefaultImplementation.IntegrationTests
{
    [TestFixture]
    public class ContentGroupDataTests
    {
        private static Random _random = new System.Random();

        [Test]
        public void CanCRUD()
        {
            var data = new ContentGroupData();

            var group = new ContentGroup();
            group.Name = "Funky" + _random.Next(int.MaxValue);

            data.Save(group);
            group.Id.IsGreaterThan(0, "The id was not assigned.");

            group.Name = group.Name + _random.Next(int.MaxValue);
            data.Save(group);

            var updatedGroup = data.Get(group.Id);
            updatedGroup.Name.IsEqualTo(group.Name, "The name was not updated.");

            data.Delete(updatedGroup.Id);
            var deletedGroup = data.Get(group.Id);
            Assert.IsNull(deletedGroup, "The group was not deleted.");
        }

        /// <summary>
        /// Note: This test kinda sucks.
        /// </summary>
        [Test]
        public void CanGetList()
        {
            var data = new ContentGroupData();

            var group0 = new ContentGroup();
            group0.Name = "Chicken" + _random.Next(int.MaxValue);
            data.Save(group0);
            group0.Id.IsGreaterThan(0, "Group0 was not assigned an id.");

            var group1 = new ContentGroup();
            group1.Name = "Turkey" + _random.Next(int.MaxValue);
            data.Save(group1);
            group1.Id.IsGreaterThan(0, "Group1 was not assigned an id.");

            var list = data.GetList();
            list.Count.IsGreaterThan(1, "Expected at least two groups.");

            data.Delete(group0.Id);
            data.Delete(group1.Id);
        }
    }
}
